package net.aspw.client.features.module.impl.exploit

import io.netty.buffer.Unpooled
import net.aspw.client.Launch
import net.aspw.client.event.*
import net.aspw.client.features.module.Module
import net.aspw.client.features.module.ModuleCategory
import net.aspw.client.features.module.ModuleInfo
import net.aspw.client.features.module.impl.combat.KillAura
import net.aspw.client.features.module.impl.movement.Flight
import net.aspw.client.features.module.impl.movement.LongJump
import net.aspw.client.features.module.impl.movement.Speed
import net.aspw.client.features.module.impl.player.Scaffold
import net.aspw.client.utils.*
import net.aspw.client.utils.misc.RandomUtils
import net.aspw.client.utils.render.RenderUtils
import net.aspw.client.utils.render.Stencil
import net.aspw.client.utils.timer.MSTimer
import net.aspw.client.value.BoolValue
import net.aspw.client.value.IntegerValue
import net.aspw.client.value.ListValue
import net.aspw.client.visual.font.semi.Fonts
import net.aspw.client.visual.font.smooth.FontLoaders
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.entity.Entity
import net.minecraft.entity.item.EntityBoat
import net.minecraft.entity.player.PlayerCapabilities
import net.minecraft.init.Items
import net.minecraft.item.ItemSword
import net.minecraft.network.Packet
import net.minecraft.network.PacketBuffer
import net.minecraft.network.play.INetHandlerPlayClient
import net.minecraft.network.play.INetHandlerPlayServer
import net.minecraft.network.play.client.*
import net.minecraft.network.play.client.C03PacketPlayer.*
import net.minecraft.network.play.server.S07PacketRespawn
import net.minecraft.network.play.server.S08PacketPlayerPosLook
import net.minecraft.network.play.server.S3EPacketTeams
import net.minecraft.network.play.server.S42PacketCombatEvent
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import java.awt.Color
import java.io.ByteArrayOutputStream
import java.io.DataOutputStream
import java.io.IOException
import java.util.*
import java.util.concurrent.LinkedBlockingQueue
import kotlin.math.round
import kotlin.math.sqrt

@ModuleInfo(name = "Disabler", category = ModuleCategory.EXPLOIT)
class Disabler : Module() {

    private val basic = BoolValue("Basic", false)
    private val vanilladesync = BoolValue("Vanilla-Desync", false)
    private val silentaccept = BoolValue("Silent-Accept", false)
    private val shotbow = BoolValue("ShotBow", false)
    private val funcraftstaff = BoolValue("Funcraft-Staff", false)
    private val blockdrop = BoolValue("BlockDrop", false)
    private val hycraft = BoolValue("Hycraft", false)
    private val inventoryspoof = BoolValue("Inventory-Spoof", false)
    private val jump = BoolValue("Jump", false)
    private val blockplacement = BoolValue("BlockPlacement", false)
    private val boat = BoolValue("Boat", false)
    private val latestverus = BoolValue("Latest-Verus", false)
    private val verussemi = BoolValue("Verus-Semi", false)
    private val veruscombat = BoolValue("Verus-Combat", false)
    private val gwencombat = BoolValue("Gwen-Combat", false)
    private val spartancombat = BoolValue("Spartan-Combat", false)
    private val pingspoof = BoolValue("Ping-Spoof", false)
    private val flag = BoolValue("Flag", false)
    private val input = BoolValue("Input", false)
    private val noswing = BoolValue("NoSwing", false)
    private val payload = BoolValue("Payload", false)
    private val spectate = BoolValue("Spectate", false)
    private val mushmc = BoolValue("MushMC", false)
    private val buzzsemi = BoolValue("Buzz-Semi", false)
    private val vulcanstrafe = BoolValue("Vulcan-Strafe", false)
    private val vulcancombat = BoolValue("Vulcan-Combat", false)
    private val aac5 = BoolValue("AAC5", false)
    private val placechecks = BoolValue("PlaceChecks", false)
    private val afkchecks = BoolValue("AFKChecks", false)
    private val matrix = BoolValue("Matrix", false)
    private val oldmatrix = BoolValue("Old-Matrix", false)
    private val oldwatchdog1 = BoolValue("Old-Watchdog1", false)
    private val oldwatchdog2 = BoolValue("Old-Watchdog2", false)

    private val minpsf: IntegerValue = object :
        IntegerValue("PingSpoof-MinDelay", 200, 0, 10000, "ms", { pingspoof.get() }) {
        override fun onChanged(oldValue: Int, newValue: Int) {
            val v = maxpsf.get()
            if (v < newValue) set(v)
        }
    }
    private val maxpsf: IntegerValue = object :
        IntegerValue("PingSpoof-MaxDelay", 250, 0, 10000, "ms", { pingspoof.get() }) {
        override fun onChanged(oldValue: Int, newValue: Int) {
            val v = minpsf.get()
            if (v > newValue) set(v)
        }
    }
    private val psfStartSendMode = ListValue(
        "PingSpoof-StartSendMode",
        arrayOf("All", "First"),
        "All"
    ) { pingspoof.get() }
    private val psfSendMode =
        ListValue("PingSpoof-SendMode", arrayOf("All", "First"), "All") { pingspoof.get() }
    private val psfWorldDelay =
        IntegerValue("PingSpoof-WorldDelay", 15000, 0, 30000, "ms") { pingspoof.get() }

    // flag
    private val flagMode =
        ListValue("Flag-Mode", arrayOf("Edit", "Packet"), "Edit") { flag.get() }
    private val flagTick = IntegerValue("Flag-TickDelay", 25, 1, 200) { flag.get() }
    private val flagSilent = BoolValue("Flag-SilentMode", false) { flag.get() }

    // matrix
    private val matrixNoCheck = BoolValue("Matrix-NoModuleCheck", false) { matrix.get() }
    private val matrixNewMoveFix = BoolValue("Matrix-NewMoveFix", true) { matrix.get() }
    private val matrixOldMoveFix = BoolValue("Matrix-OldMoveFix", false) { matrix.get() }
    private val matrixMoveOnly = BoolValue("Matrix-MoveOnly", false) { matrix.get() }
    private val matrixNoMovePacket = BoolValue("Matrix-NoMovePacket", true) { matrix.get() }
    private val matrixHotbarChange = BoolValue("Matrix-HotbarChange", true) { matrix.get() }

    // vulcancombat
    private val compDecValue = BoolValue("VulcanDecrease", true) { vulcancombat.get() }
    private val statDecValue =
        IntegerValue("VulcanDecreaseDelay", 1500, 500, 2500) { vulcancombat.get() && compDecValue.get() }
    private val dynamicValue = BoolValue("VulcanDynamicDelay", true) { vulcancombat.get() }
    private val decDelayMinValue =
        IntegerValue("VulcanMinDelay", 4500, 2000, 8000) { vulcancombat.get() && dynamicValue.get() }
    private val decDelayMaxValue =
        IntegerValue("VulcanMaxDelay", 5500, 2000, 8000) { vulcancombat.get() && dynamicValue.get() }
    private val minBuffValue = IntegerValue("VulcanMinBuff", 5, 0, 12) { vulcancombat.get() }
    private val noC0BValue = BoolValue("NoC0BPacket", false) { vulcancombat.get() }

    // verus
    private val verusLobbyValue = BoolValue(
        "LobbyCheck",
        false
    ) { latestverus.get() || verussemi.get() }
    private val verusFlagValue = BoolValue("Verus-Flag", true) { latestverus.get() }
    private val verusSlientFlagApplyValue =
        BoolValue("Verus-SilentFlagApply", false) { latestverus.get() }
    private val verusBufferSizeValue =
        IntegerValue("Verus-QueueActiveSize", 300, 0, 1000) { latestverus.get() }
    private val verusFlagDelayValue =
        IntegerValue("Verus-FlagDelay", 40, 40, 120, " tick") { latestverus.get() }
    private val verusAntiFlyCheck = BoolValue("Verus-AntiFlight", true) { latestverus.get() }
    private val verusFakeInput = BoolValue("Verus-FakeInput", true) { latestverus.get() }
    private val verusValidPos = BoolValue("Verus-ValidPosition", true) { latestverus.get() }

    // watchdog
    private val waitingDisplayMode = ListValue(
        "Waiting-Display",
        arrayOf("Top", "Middle", "Notification", "Chat", "None"),
        "Top"
    ) { oldwatchdog1.get() }
    private val testFeature = BoolValue("PingSpoof", true) { oldwatchdog1.get() }
    private val testDelay =
        IntegerValue("Delay", 400, 0, 1000, "ms") { oldwatchdog1.get() && testFeature.get() }

    private val rotationChanger = BoolValue("RotationDisabler", true) { oldwatchdog2.get() }
    private val c00Disabler = BoolValue("KeepAliveDisabler", false) { oldwatchdog2.get() }
    private val c0BDisabler = BoolValue("C0BDisabler", true) { oldwatchdog2.get() }
    private val watchDogAntiBan = BoolValue("LessFlag", false) { oldwatchdog2.get() }
    private val noC03 = BoolValue("NoC03Packet", true) { oldwatchdog2.get() }
    private val strafeDisabler = BoolValue("StrafeDisabler", true) { oldwatchdog2.get() }
    private val strafePackets =
        IntegerValue("StrafeDisablerPacketAmount", 70, 60, 120) { oldwatchdog2.get() && strafeDisabler.get() }
    private val timerA = BoolValue("Timer1", true) { oldwatchdog2.get() }
    private val timerB = BoolValue("Timer2", false) { oldwatchdog2.get() }
    private var x = 0.0
    private var y = 0.0
    private var z = 0.0
    private val packets = LinkedBlockingQueue<Packet<INetHandlerPlayServer>>()
    private val timerCancelDelay = MSTimer()
    private val timerCancelTimer = MSTimer()
    private var timerShouldCancel = true
    private var inCage = true
    private var canBlink = true
    private var lockRotation: Rotation? = null
    private var disabling = false
    private var shouldDelay = false
    private val packetz = LinkedBlockingQueue<Packet<INetHandlerPlayClient>>()

    // debug
    private val debugValue = BoolValue("Debug", false)

    // sus
    private var rotatingSpeed = 0F

    // variables
    private val keepAlives = arrayListOf<C00PacketKeepAlive>()
    private val transactions = arrayListOf<C0FPacketConfirmTransaction>()
    private val packetQueue = LinkedList<C0FPacketConfirmTransaction>()
    private val anotherQueue = LinkedList<C00PacketKeepAlive>()
    private val playerQueue = LinkedList<C03PacketPlayer>()

    private val packetBus = hashMapOf<Long, Packet<INetHandlerPlayServer>>()
    private val queueBus = LinkedList<Packet<INetHandlerPlayServer>>()
    private val packetBuffer = LinkedList<Packet<INetHandlerPlayServer>>()

    private val posLookInstance = PosLookInstance()

    private val msTimer = MSTimer()
    private val wdTimer = MSTimer()
    private val benTimer = MSTimer()

    private val pulseTimer = MSTimer()

    private var alrSendY = false
    private var alrSprint = false

    private var expectedSetback = false
    private var flagged = false

    private var packetCount = 0

    private var lastMotionX = 0.0
    private var lastMotionY = 0.0
    private var lastMotionZ = 0.0
    private var pendingFlagApplyPacket = false

    private var sendDelay = 0
    private var shouldActive = false
    private var benHittingLean = false
    private var pre = false

    private var transCount = 0
    private var counter = 0
    private var canModify = false

    private var lastTick = 0

    private var s08count = 0
    private var ticking = 0

    private var lastUid = 0
    private var currentTrans = 0

    private var currentDelay = 5000
    private var currentBuffer = 4
    private var currentDec = -1
    private val lagTimer = MSTimer()
    private val decTimer = MSTimer()
    private var runReset = false

    fun isMoving(): Boolean =
        (mc.thePlayer != null && (mc.thePlayer.movementInput.moveForward != 0F || mc.thePlayer.movementInput.moveStrafe != 0F || mc.thePlayer.movementInput.sneak || mc.thePlayer.movementInput.jump))

    private fun debug(s: String, force: Boolean = false) {
        if (debugValue.get() || force)
            ClientUtils.displayChatMessage(Launch.CLIENT_CHAT + "§f$s")
    }

    private fun shouldRun(): Boolean =
        mc.thePlayer != null && mc.thePlayer.inventory != null && (!verusLobbyValue.get() || !mc.thePlayer.inventory.hasItem(
            Items.compass
        )) && mc.thePlayer.ticksExisted > 5

    private fun isInventory(action: Short): Boolean = action in 1..99

    override fun onEnable() {
        pendingFlagApplyPacket = false

        if (oldwatchdog2.get()) {
            counter = 0
            inCage = true
            x = 0.0
            y = 0.0
            z = 0.0
            timerCancelDelay.reset()
            timerCancelTimer.reset()
        }

        if (boat.get()) {
            debug("Place 2 boats next to each other and right click to use it!")
        }

        packetBuffer.clear()
        keepAlives.clear()
        transactions.clear()
        packetQueue.clear()
        anotherQueue.clear()
        playerQueue.clear()
        packetBus.clear()
        queueBus.clear()

        s08count = 0
        packetCount = 0

        pulseTimer.reset()
        msTimer.reset()
        wdTimer.reset()
        benTimer.reset()
        canModify = false
        expectedSetback = false
        shouldActive = false
        alrSendY = false
        alrSprint = false
        transCount = 0
        lastTick = 0
        ticking = 0

        lastUid = 0
        posLookInstance.reset()

        benHittingLean = false

        rotatingSpeed = 0F
    }

    override fun onDisable() {
        shouldDelay = false
        flagged = false
        pre = false
        pendingFlagApplyPacket = false
        keepAlives.forEach {
            PacketUtils.sendPacketNoEvent(it)
        }
        transactions.forEach {
            PacketUtils.sendPacketNoEvent(it)
        }
        while (!packetz.isEmpty()) {
            PacketUtils.handlePacket(packets.take() as Packet<INetHandlerPlayClient?>)
        }
        disabling = false
        packetBuffer.clear()
        keepAlives.clear()
        transactions.clear()
        packetQueue.clear()
        anotherQueue.clear()
        packetBus.clear()
        lockRotation = null

        if (inventoryspoof.get() || shotbow.get()) {
            PacketUtils.sendPacketNoEvent(C0DPacketCloseWindow())
        }

        if (vulcancombat.get()) {
            updateLagTime()
            BlinkUtils.releasePacket(packetType = "C0FPacketConfirmTransaction")
            BlinkUtils.setBlinkState(packetTransaction = false)
        }

        if (oldwatchdog1.get()) {
            anotherQueue.forEach { PacketUtils.sendPacketNoEvent(it) }
            packetQueue.forEach { PacketUtils.sendPacketNoEvent(it) }
        }

        if (pingspoof.get()) {
            // make sure not to cause weird flag
            for (p in queueBus)
                PacketUtils.sendPacketNoEvent(p)
        }
        queueBus.clear()

        msTimer.reset()

        mc.timer.timerSpeed = 1F
    }

    @EventTarget
    fun onWorld(event: WorldEvent) {
        if (oldwatchdog2.get()) {
            counter = 0
            inCage = true
        }

        if (vulcancombat.get()) {
            BlinkUtils.clearPacket(packetType = "C0FPacketConfirmTransaction")
            currentTrans = 0
            updateLagTime()
            runReset = noC0BValue.get()
        }

        packetBuffer.clear()
        transactions.clear()
        keepAlives.clear()
        packetQueue.clear()
        anotherQueue.clear()
        playerQueue.clear()
        packetBus.clear()
        queueBus.clear()
        canModify = false

        s08count = 0

        msTimer.reset()
        wdTimer.reset()
        benTimer.reset()
        expectedSetback = false
        shouldActive = false
        alrSendY = false
        alrSprint = false
        benHittingLean = false
        transCount = 0
        counter = 0
        lastTick = 0
        ticking = 0
        lastUid = 0
        posLookInstance.reset()

        rotatingSpeed = 0F
    }

    @EventTarget
    fun onRender2D(event: Render2DEvent) {
        if (!shouldActive) {
            val sc = ScaledResolution(mc)
            val strength =
                (msTimer.hasTimeLeft(psfWorldDelay.get().toLong()).toFloat() / psfWorldDelay.get().toFloat()).coerceIn(
                    0F,
                    1F
                )

            if (pingspoof.get()) {
                Stencil.write(true)
                RenderUtils.drawRoundedRect(
                    sc.scaledWidth / 2F - 50F,
                    35F,
                    sc.scaledWidth / 2F + 50F,
                    55F,
                    10F,
                    Color(0, 0, 0, 140).rgb
                )
                Stencil.erase(true)
                RenderUtils.drawRect(
                    sc.scaledWidth / 2F - 50F,
                    35F,
                    sc.scaledWidth / 2F - 50F + 100F * strength,
                    55F,
                    Color(0, 111, 255, 70).rgb
                )
                Stencil.dispose()
                FontLoaders.SF20.drawCenteredString(
                    "${
                        (msTimer.hasTimeLeft(psfWorldDelay.get().toLong()).toFloat() / 1000F).toInt()
                    }s left...", sc.scaledWidth / 2F, 41F, -1
                )
            }
            if ((oldwatchdog1.get() && testFeature.get()) && !ServerUtils.isHypixelLobby() && !mc.isSingleplayer
            ) {
                when (waitingDisplayMode.get().lowercase(Locale.getDefault())) {
                    "top" -> {
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F,
                            61.5F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F,
                            62.5F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F - 0.5F,
                            62F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F + 0.5F,
                            62F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F,
                            62F,
                            Color(220, 220, 60).rgb,
                            false
                        )
                    }

                    "middle" -> {
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F,
                            sc.scaledHeight / 2F + 14.5F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F,
                            sc.scaledHeight / 2F + 15.5F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F - 0.5F,
                            sc.scaledHeight / 2F + 15F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F + 0.5F,
                            sc.scaledHeight / 2F + 15F,
                            Color(0, 0, 0).rgb,
                            false
                        )
                        Fonts.minecraftFont.drawString(
                            "Disabling Watchdog...",
                            sc.scaledWidth / 2F - Fonts.minecraftFont.getStringWidth("Disabling watchdog...") / 2F,
                            sc.scaledHeight / 2F + 15F,
                            Color(220, 220, 60).rgb,
                            false
                        )
                    }
                }
            }
        }
    }

    @EventTarget
    fun onPacket(event: PacketEvent) {
        val packet = event.packet

        if (boat.get()) {
            if (mc.thePlayer.ridingEntity != null) {
                canModify = true
            }

            if (canModify && packet is C03PacketPlayer) {
                packet.onGround = true
            }
        }

        if (spectate.get()) {
            if (packet is C03PacketPlayer) {
                packet.onGround = false

                mc.netHandler.addToSendQueue(C18PacketSpectate(mc.thePlayer.uniqueID))
                mc.netHandler.addToSendQueue(C13PacketPlayerAbilities(mc.thePlayer.capabilities))
                debug("Packet C18 + C13")
            }
            if (packet is C13PacketPlayerAbilities) {
                debug("Packet C13")
                packet.isFlying = true
                packet.isInvulnerable = true
                packet.isAllowFlying = true
                packet.isCreativeMode = false
            }
        }

        if (placechecks.get()) {
            if (packet is C08PacketPlayerBlockPlacement && !mc.isIntegratedServerRunning) {
                event.cancelEvent()
                PacketUtils.sendPacketNoEvent(
                    C08PacketPlayerBlockPlacement(
                        packet.position,
                        packet.placedBlockDirection,
                        null,
                        packet.placedBlockOffsetX,
                        packet.placedBlockOffsetY,
                        packet.placedBlockOffsetZ
                    )
                )
                debug("replaced placement packet")
            }
        }

        if (vulcancombat.get()) {
            if (packet is C0BPacketEntityAction && noC0BValue.get()) {
                event.cancelEvent()
                debug("C0B-EntityAction CANCELLED")
            }
            if (packet is C0FPacketConfirmTransaction) {
                BlinkUtils.setBlinkState(packetTransaction = false)
                val transUID = (packet.uid).toInt()
                if (transUID >= -25767 && transUID <= -24769) {
                    BlinkUtils.setBlinkState(packetTransaction = true)
                    debug("C0F-PingTickCounter IN ${BlinkUtils.bufferSize(packetType = "C0FPacketConfirmTransaction")}")
                } else if (transUID == -30000) {
                    BlinkUtils.setBlinkState(packetTransaction = true)
                    debug("C0F-OnSpawn IN ${BlinkUtils.bufferSize(packetType = "C0FPacketConfirmTransaction")}")
                }
            }
        }

        if (oldwatchdog2.get()) {
            canBlink = true

            if (mc.thePlayer.ticksExisted > 200f)
                inCage = false

            //timerA
            if (timerA.get() && !inCage) {
                if (packet is C02PacketUseEntity || packet is C03PacketPlayer || packet is C07PacketPlayerDigging || packet is C08PacketPlayerBlockPlacement ||
                    packet is C0APacketAnimation || packet is C0BPacketEntityAction && mc.thePlayer.ticksExisted > strafePackets.get()
                ) {
                    if (timerShouldCancel) {
                        if (!timerCancelTimer.hasTimePassed(350)) {
                            packets.add(packet as Packet<INetHandlerPlayServer>)
                            event.cancelEvent()
                            canBlink = false
                        } else {
                            debug("Timer 1 release packets")
                            debug("Size " + packets.size.toString())
                            timerShouldCancel = false
                            while (!packets.isEmpty()) {
                                PacketUtils.sendPacketNoEvent(packets.take())
                            }
                        }
                        if ((mc.thePlayer.isUsingItem || Launch.moduleManager[KillAura::class.java]!!.autoBlockModeValue.get() != "None") && Launch.moduleManager[KillAura::class.java]!!.target != null && mc.thePlayer.heldItem != null && mc.thePlayer.heldItem.item is ItemSword
                        ) {
                            debug("Timer 1 release packets")
                            debug("Size " + packets.size.toString())
                            timerShouldCancel = false
                            while (!packets.isEmpty()) {
                                PacketUtils.sendPacketNoEvent(packets.take())
                            }
                        }
                    }
                }
            }

            //timerB
            if (timerB.get() && !inCage) {
                if (packet is C02PacketUseEntity || packet is C03PacketPlayer || packet is C07PacketPlayerDigging || packet is C08PacketPlayerBlockPlacement ||
                    packet is C0APacketAnimation || packet is C0BPacketEntityAction && mc.thePlayer.ticksExisted > strafePackets.get()
                ) {
                    if (timerShouldCancel) {
                        if (!timerCancelTimer.hasTimePassed(250)) {
                            packets.add(packet as Packet<INetHandlerPlayServer>)
                            event.cancelEvent()
                            canBlink = false
                        } else {
                            debug("Timer 2 release packets")
                            debug("Size " + packets.size.toString())
                            timerShouldCancel = false
                            while (!packets.isEmpty()) {
                                PacketUtils.sendPacketNoEvent(packets.take())
                            }
                        }
                        if ((mc.thePlayer.isUsingItem || Launch.moduleManager[KillAura::class.java]!!.autoBlockModeValue.get() != "None") && Launch.moduleManager[KillAura::class.java]!!.target != null && mc.thePlayer.heldItem != null && mc.thePlayer.heldItem.item is ItemSword
                        ) {
                            debug("Timer 2 release packets")
                            debug("Size " + packets.size.toString())
                            timerShouldCancel = false
                            while (!packets.isEmpty()) {
                                PacketUtils.sendPacketNoEvent(packets.take())
                            }
                        }
                    }
                }
            }


            // noC03
            if (packet is C03PacketPlayer && !(packet is C05PacketPlayerLook || packet is C06PacketPlayerPosLook || packet is C04PacketPlayerPosition) && noC03.get()) {
                event.cancelEvent()
                canBlink = false
            }

            // strafe disabler
            if (strafeDisabler.get() && (mc.thePlayer.ticksExisted < strafePackets.get()) && packet is C03PacketPlayer && (mc.thePlayer.ticksExisted % 15 != 0)) {
                event.cancelEvent()
                canBlink = false
            }

            // anti ban
            if (watchDogAntiBan.get() || (strafeDisabler.get() && (mc.thePlayer.ticksExisted < strafePackets.get()))) {
                if (event.packet is C06PacketPlayerPosLook && mc.thePlayer.onGround && mc.thePlayer.fallDistance > 10) {
                    if (counter > 0) {
                        if (event.packet.x == x && event.packet.y == y && event.packet.z == z) {
                            mc.netHandler.networkManager.sendPacket(
                                C04PacketPlayerPosition(
                                    event.packet.x,
                                    event.packet.y,
                                    event.packet.z,
                                    event.packet.onGround
                                )
                            )
                            debug("Packet C04")
                            event.cancelEvent()
                        }
                    }
                    counter += 1
                }

                if (event.packet is S08PacketPlayerPosLook) {
                    val s08 = event.packet
                    x = s08.x
                    y = s08.y
                    z = s08.z
                    debug("Receive S08")
                }

                if (event.packet is S07PacketRespawn) {
                    counter = 0
                }
            }
        }

        if (afkchecks.get()) {
            if (Launch.moduleManager.getModule(LongJump::class.java)?.state!! && Launch.moduleManager.getModule(LongJump::class.java)?.modeValue?.get()
                    .equals(
                        "VerusHigh",
                        true
                    ) || Launch.moduleManager.getModule(KillAura::class.java)?.state!! && Launch.moduleManager.getModule(
                    KillAura::class.java
                )?.target != null
            ) {
                debug("unavailable")
            } else {
                if (packet is C03PacketPlayer) {
                    if (mc.thePlayer.motionY == 0.0 || mc.thePlayer.onGround || mc.thePlayer.isCollidedVertically) {
                        packet.onGround = true
                        debug("fix ground")
                    }
                }
                if (packet is C03PacketPlayer) {
                    if (packet !is C04PacketPlayerPosition && packet !is C05PacketPlayerLook && packet !is C06PacketPlayerPosLook) {
                        packetCount++
                        if (packetCount >= 2) {
                            event.cancelEvent()
                            debug("cancel nigga 2")
                        }
                    } else {
                        packetCount = 0
                        debug("set 0")
                    }
                }
            }
        }

        if (shotbow.get()) {
            if (packet is C0DPacketCloseWindow) {
                event.cancelEvent()
                debug("Activated Disabler!")
            }
            if (packet is C03PacketPlayer)
                packet.onGround = true
            if (packet is S08PacketPlayerPosLook) {
                if (mc.thePlayer == null || mc.thePlayer.ticksExisted <= 0) return
                val x = packet.getX() - mc.thePlayer.posX
                val y = packet.getY() - mc.thePlayer.posY
                val z = packet.getZ() - mc.thePlayer.posZ
                val diff = sqrt(x * x + y * y + z * z)
                if (diff <= 20) {
                    event.cancelEvent()
                    PacketUtils.sendPacketNoEvent(
                        C06PacketPlayerPosLook(
                            packet.x,
                            packet.y,
                            packet.z,
                            packet.yaw,
                            packet.pitch,
                            true
                        )
                    )
                    debug("modified c06")
                    PacketUtils.sendPacketNoEvent(
                        C04PacketPlayerPosition(
                            mc.thePlayer.posX,
                            mc.thePlayer.posY + 0.2,
                            mc.thePlayer.posZ,
                            false
                        )
                    )
                    PacketUtils.sendPacketNoEvent(
                        C04PacketPlayerPosition(
                            mc.thePlayer.posX,
                            mc.thePlayer.posY,
                            mc.thePlayer.posZ,
                            true
                        )
                    )
                    debug("cancel c04")
                }
            }
        }

        if (inventoryspoof.get()) {
            if (packet is C0DPacketCloseWindow) {
                event.cancelEvent()
                debug("spoof inventory")
            }
        }

        if (mushmc.get()) {
            if (packet is C16PacketClientStatus || packet is C0APacketAnimation || packet is S42PacketCombatEvent || packet is S3EPacketTeams) {
                event.cancelEvent()
                debug("funny packet")
            }
            mc.thePlayer.capabilities.isCreativeMode = true
        }

        if (input.get()) {
            PacketUtils.sendPacketNoEvent(C0CPacketInput(0.98f, 0f, true, true))
            debug("input")
        }

        if (noswing.get()) {
            if (packet is C0APacketAnimation) {
                event.cancelEvent()
                debug("cancelled c0a")
            }
        }

        if (aac5.get()) {
            val packetPlayerAbilities = C13PacketPlayerAbilities()
            packetPlayerAbilities.isFlying = true
            PacketUtils.sendPacketSilent(packetPlayerAbilities)
            if (mc.thePlayer.ticksExisted % 40 == 0) PacketUtils.sendPacketSilent(
                C04PacketPlayerPosition(
                    0.0,
                    258382.0,
                    0.0,
                    true
                )
            )
            debug("Funny packet Activated!")
        }

        if (vulcanstrafe.get()) {
            if (packet is C03PacketPlayer) {
                mc.thePlayer.sendQueue.addToSendQueue(
                    C07PacketPlayerDigging(
                        C07PacketPlayerDigging.Action.STOP_DESTROY_BLOCK, BlockPos(
                            mc.thePlayer.posX, mc.thePlayer.posY - 1.0, mc.thePlayer.posZ
                        ), EnumFacing.UP
                    )
                )
                debug("OMG")
            }
        }

        if (spartancombat.get()) {
            if (packet is C00PacketKeepAlive && (keepAlives.size <= 0 || packet != keepAlives[keepAlives.size - 1])) {
                debug("c00 added")
                keepAlives.add(packet)
                event.cancelEvent()
            }
            if (packet is C0FPacketConfirmTransaction && (transactions.size <= 0 || packet != transactions[transactions.size - 1])) {
                debug("c0f added")
                transactions.add(packet)
                event.cancelEvent()
            }
        }

        if (funcraftstaff.get()) {
            if (packet is C03PacketPlayer) {
                mc.thePlayer.sendQueue.networkManager.sendPacket(C00PacketKeepAlive(-2))
                debug("LOL")
            }
        }

        if (basic.get()) {
            if (packet is C00PacketKeepAlive) {
                debug("cancel c00")
                event.cancelEvent()
            }
            if (packet is C0FPacketConfirmTransaction) {
                debug("cancel c0f")
                event.cancelEvent()
            }
        }

        if (oldmatrix.get()) {
            if (packet is C03PacketPlayer && mc.thePlayer.ticksExisted % 15 == 0) {
                try {
                    val b = ByteArrayOutputStream()
                    val _out = DataOutputStream(b)
                    _out.writeUTF(mc.thePlayer.gameProfile.name)
                    val buf = PacketBuffer(Unpooled.buffer())
                    buf.writeBytes(b.toByteArray())
                    mc.netHandler.addToSendQueue(C17PacketCustomPayload("matrix:geyser", buf))

                    debug("Sent Matrix spoof packet.")
                } catch (e: IOException) {
                    debug("Error occurred.")
                }
            }
        }

        if (blockdrop.get()) {
            if (packet is C00PacketKeepAlive && (keepAlives.size <= 0 || packet != keepAlives[keepAlives.size - 1])) {
                debug("c00 added")
                keepAlives.add(packet)
                event.cancelEvent()
            }
            if (packet is C0FPacketConfirmTransaction && (transactions.size <= 0 || packet != transactions[transactions.size - 1])) {
                debug("c0f added")
                transactions.add(packet)
                event.cancelEvent()
            }
            if (packet is C13PacketPlayerAbilities) {
                event.cancelEvent()
            }
        }

        if (jump.get()) {
            if (packet is C03PacketPlayer) {
                val capabilities = PlayerCapabilities()
                capabilities.disableDamage = false
                capabilities.isFlying = true
                capabilities.allowFlying = false
                capabilities.isCreativeMode = false
                mc.netHandler.addToSendQueue(C13PacketPlayerAbilities(capabilities))
                debug("jump added")
            }
        }

        if (gwencombat.get()) {
            if (packet is C00PacketKeepAlive) {
                event.cancelEvent()
                PacketUtils.sendPacketNoEvent(
                    C00PacketKeepAlive(
                        packet.key - RandomUtils.nextInt(
                            1000,
                            2147483647
                        )
                    )
                )
                debug("cancel c00")
            }
        }

        if (latestverus.get()) {
            if (!shouldRun()) {
                msTimer.reset()
                packetQueue.clear()
                return
            }

            if (packet is C0FPacketConfirmTransaction && !isInventory(packet.uid)) {
                packetQueue.add(packet)
                event.cancelEvent()
                if (packetQueue.size > verusBufferSizeValue.get()) {
                    if (!shouldActive) {
                        shouldActive = true
                        chat("Successfully Verus Disabled!")
                    }
                    PacketUtils.sendPacketNoEvent(packetQueue.poll())
                }
                debug("c0f, ${packetQueue.size}")
            }

            if (packet is C0BPacketEntityAction) {
                event.cancelEvent()
                debug("ignored packet action")
            }

            if (packet is C03PacketPlayer) {
                if (verusFlagValue.get() && mc.thePlayer.ticksExisted % verusFlagDelayValue.get() == 0) {
                    debug("modified c03")
                    packet.y -= 11.015625 // just phase into ground instead (minimum to flag)
                    packet.onGround = false
                    packet.isMoving = false
                }
                if (verusValidPos.get()) {
                    if (packet.y % 0.015625 == 0.0)
                        packet.onGround = true
                }
            }

            if (packet is S08PacketPlayerPosLook && verusSlientFlagApplyValue.get()) {
                val x = packet.x - mc.thePlayer.posX
                val y = packet.y - mc.thePlayer.posY
                val z = packet.z - mc.thePlayer.posZ
                val diff = sqrt(x * x + y * y + z * z)
                if (diff <= 8) {
                    event.cancelEvent()
                    // verus, why
                    debug("flag silent accept")
                    PacketUtils.sendPacketNoEvent(
                        C06PacketPlayerPosLook(
                            packet.x,
                            packet.y,
                            packet.z,
                            packet.getYaw(),
                            packet.getPitch(),
                            false
                        )
                    )
                }
            }
        }

        if (silentaccept.get()) {
            if (packet is C03PacketPlayer) {
                val yPos = round(mc.thePlayer.posY / 0.015625) * 0.015625
                mc.thePlayer.setPosition(mc.thePlayer.posX, yPos, mc.thePlayer.posZ)

                if (mc.thePlayer.ticksExisted % 45 == 0) {
                    debug("flag")
                    PacketUtils.sendPacketNoEvent(
                        C04PacketPlayerPosition(
                            mc.thePlayer.posX,
                            mc.thePlayer.posY,
                            mc.thePlayer.posZ,
                            true
                        )
                    )
                    PacketUtils.sendPacketNoEvent(
                        C04PacketPlayerPosition(
                            mc.thePlayer.posX,
                            mc.thePlayer.posY - 11.725,
                            mc.thePlayer.posZ,
                            false
                        )
                    )
                    PacketUtils.sendPacketNoEvent(
                        C04PacketPlayerPosition(
                            mc.thePlayer.posX,
                            mc.thePlayer.posY,
                            mc.thePlayer.posZ,
                            true
                        )
                    )
                }
            }

            if (packet is S08PacketPlayerPosLook) {
                if (mc.thePlayer == null || mc.thePlayer.ticksExisted <= 0) return

                val x = packet.getX() - mc.thePlayer.posX
                val y = packet.getY() - mc.thePlayer.posY
                val z = packet.getZ() - mc.thePlayer.posZ
                val diff = sqrt(x * x + y * y + z * z)
                if (diff <= 8) {
                    event.cancelEvent()
                    PacketUtils.sendPacketNoEvent(
                        C06PacketPlayerPosLook(
                            packet.getX(),
                            packet.getY(),
                            packet.getZ(),
                            packet.getYaw(),
                            packet.getPitch(),
                            true
                        )
                    )

                    debug("silent s08 accept")
                }
            }

            if (packet is C0FPacketConfirmTransaction && !isInventory(packet.uid)) {
                repeat(4) {
                    packetQueue.add(packet)
                }
                event.cancelEvent()
                debug("c0f dupe: 4x")
            }
        }

        if (buzzsemi.get()) {
            if (packet is C0FPacketConfirmTransaction) {
                repeat(5) {
                    packetQueue.add(packet)
                }
                event.cancelEvent()
                debug("c0f dupe: 5x")
            }
        }

        if (veruscombat.get()) {
            if (packet is C0FPacketConfirmTransaction) {
                event.cancelEvent()
                debug("cancel c0f")
            } else if (packet is C0BPacketEntityAction) {
                event.cancelEvent()
                debug("cancel c0b")
            }
        }

        if (verussemi.get()) {
            if (!shouldRun()) {
                queueBus.clear()
                return
            }

            if (packet is C0BPacketEntityAction) {
                event.cancelEvent()
                debug("cancel action")
            }

            if (packet is S08PacketPlayerPosLook) {
                if (mc.thePlayer.getDistance(packet.x, packet.y, packet.z) < 8) {
                    PacketUtils.sendPacketNoEvent(
                        C06PacketPlayerPosLook(
                            packet.x,
                            packet.y,
                            packet.z,
                            packet.yaw,
                            packet.pitch,
                            false
                        )
                    )
                    event.cancelEvent()
                    debug("silent flag")
                }
            }

            if (packet is C00PacketKeepAlive || (packet is C0FPacketConfirmTransaction && !isInventory(packet.uid))) {
                queueBus.add(packet as Packet<INetHandlerPlayServer>)
                event.cancelEvent()

                debug("c0f or c00, ${queueBus.size}")

                if (queueBus.size > 300) {
                    PacketUtils.sendPacketNoEvent(queueBus.poll())
                    debug("poll")
                }
            }

            if (packet is C03PacketPlayer) {
                if (mc.thePlayer.ticksExisted % 20 == 0) {
                    PacketUtils.sendPacketNoEvent(C0CPacketInput(0.98f, 0.98f, false, false))
                    debug("c18 and c0c")
                }

                if (mc.thePlayer.ticksExisted % 45 == 0) {
                    packet.y = -0.015625
                    packet.onGround = false
                    packet.isMoving = false
                    debug("flag packet")
                }
            }
        }

        if (flag.get()) {
            if (packet is C03PacketPlayer && flagMode.get().equals(
                    "edit",
                    true
                ) && mc.thePlayer.ticksExisted > 0 && mc.thePlayer.ticksExisted % flagTick.get() == 0
            ) {
                packet.isMoving = false
                packet.onGround = false
                packet.y = -0.08

                debug("flagged")
            }
            if (packet is S08PacketPlayerPosLook && flagSilent.get()) {
                if (mc.thePlayer == null || mc.thePlayer.ticksExisted <= 0) return

                val x = packet.getX() - mc.thePlayer.posX
                val y = packet.getY() - mc.thePlayer.posY
                val z = packet.getZ() - mc.thePlayer.posZ
                val diff = sqrt(x * x + y * y + z * z)
                if (diff <= 8) {
                    event.cancelEvent()
                    PacketUtils.sendPacketNoEvent(
                        C06PacketPlayerPosLook(
                            packet.getX(),
                            packet.getY(),
                            packet.getZ(),
                            packet.getYaw(),
                            packet.getPitch(),
                            true
                        )
                    )

                    debug("silent s08 accept")
                }
            }
        }

        if (pingspoof.get()) {
            if (packet is C0FPacketConfirmTransaction && !isInventory(packet.uid)) {
                queueBus.add(packet)
                event.cancelEvent()

                debug("c0f added, action id ${packet.uid}, target id ${packet.windowId}")
            }
            if (packet is C00PacketKeepAlive) {
                queueBus.add(packet)
                event.cancelEvent()

                debug("c00 added, key ${packet.key}")
            }
        }

        if (matrix.get()) {
            if (matrixNoCheck.get() || Launch.moduleManager.getModule(Speed::class.java)!!.state || Launch.moduleManager.getModule(
                    Flight::class.java
                )!!.state
            ) {
                if (packet is C03PacketPlayer) {
                    if (matrixNoMovePacket.get() && !packet.isMoving) {
                        event.cancelEvent()
                        debug("no move, cancelled")
                        return
                    }
                    if (matrixOldMoveFix.get()) {
                        // almost completely disable strafe check, nofall
                        packet.onGround = true
                        if (!packet.rotating) { // fix fly sometimes doesn't land properly since most mc servers all refer to C04, C05, C06 as C03s aka. PacketPlayerInFlying.
                            packet.rotating = true
                            packet.yaw = mc.thePlayer.rotationYaw
                            packet.pitch = mc.thePlayer.rotationPitch
                        }
                    }
                    if (matrixNewMoveFix.get()) {
                        if (packet is C06PacketPlayerPosLook && pendingFlagApplyPacket) {
                            pendingFlagApplyPacket = false
                            mc.thePlayer.motionX = lastMotionX
                            mc.thePlayer.motionY = lastMotionY
                            mc.thePlayer.motionZ = lastMotionZ
                        }
                    }
                }
            }
        }

        if (hycraft.get()) {
            if (packet is S3EPacketTeams) {
                debug("anticrash")
                event.cancelEvent()
            }
        }

        if (vanilladesync.get()) {
            if (packet is S08PacketPlayerPosLook) {
                if (!mc.netHandler.doneLoadingTerrain) {
                    debug("not loaded terrain yet")
                    return
                }
                event.cancelEvent()
                PacketUtils.sendPacketNoEvent(C04PacketPlayerPosition(packet.x, packet.y, packet.z, false))
                mc.thePlayer.setPosition(packet.x, packet.y, packet.z)
                debug("silent setback")
            }
        }
    }

    private fun updateLagTime() {
        decTimer.reset()
        lagTimer.reset()
        currentDelay =
            if (dynamicValue.get()) RandomUtils.nextInt(decDelayMinValue.get(), decDelayMaxValue.get()) else 5000
        currentDec = if (compDecValue.get()) statDecValue.get() else -1
        currentBuffer = minBuffValue.get()
    }

    private fun getNearBoat(): Entity? {
        val entities = mc.theWorld.loadedEntityList
        for (entity_ in entities) {
            if (entity_ is EntityBoat) {
                if (entity_ != mc.thePlayer.ridingEntity) {
                    return entity_
                }
            }
        }
        return null
    }

    private fun flush(check: Boolean) {
        if ((if (check) psfSendMode.get() else psfStartSendMode.get()).equals("all", true))
            while (queueBus.size > 0) {
                PacketUtils.sendPacketNoEvent(queueBus.poll())
            }
        else
            PacketUtils.sendPacketNoEvent(queueBus.poll())
    }

    @EventTarget(priority = 2)
    fun onMotion(event: MotionEvent) {
        if (payload.get()) {
            if (event.eventState != EventState.POST) {
                PacketUtils.sendPacketNoEvent(
                    C17PacketCustomPayload(
                        "40413eb1",
                        PacketBuffer(Unpooled.wrappedBuffer(byteArrayOf(8, 52, 48, 52, 49, 51, 101, 98, 49)))
                    )
                )
                debug("funny")
            }
        }

        if (oldwatchdog2.get()) {
            if (rotationChanger.get() && !Launch.moduleManager[Scaffold::class.java]!!.state && !Launch.moduleManager[KillAura::class.java]!!.state) {
                RotationUtils.setTargetRotation(
                    Rotation(MovementUtils.getRawDirection(), RotationUtils.cameraPitch),
                    10
                )
            }
        }

        if (oldwatchdog1.get()) {
            if (event.eventState == EventState.PRE) {
                if (mc.isSingleplayer) return
                if (testFeature.get() && !ServerUtils.isHypixelLobby()) {
                    if (shouldActive && wdTimer.hasTimePassed(testDelay.get().toLong())) {
                        while (!anotherQueue.isEmpty()) {
                            PacketUtils.sendPacketNoEvent(anotherQueue.poll())
                            debug("c00, ${anotherQueue.size}")
                        }
                        while (!packetQueue.isEmpty()) {
                            PacketUtils.sendPacketNoEvent(packetQueue.poll())
                            debug("c0f, ${packetQueue.size}")
                        }
                    }
                }
            }
        }

        if (event.eventState == EventState.POST && (!matrixMoveOnly.get() || isMoving())) // check post event
            if (matrix.get()) {
                if (matrixNoCheck.get() || Launch.moduleManager.getModule(Flight::class.java)!!.state || Launch.moduleManager.getModule(
                        Speed::class.java
                    )!!.state
                ) {
                    var changed = false
                    if (matrixHotbarChange.get()) for (i in 0..8) {
                        // find empty inventory slot
                        if (mc.thePlayer.inventory.mainInventory[i] == null && i != mc.thePlayer.inventory.currentItem) {
                            PacketUtils.sendPacketNoEvent(C09PacketHeldItemChange(i))
                            changed = true
                            debug("found empty slot $i, switching")
                            break
                        }
                    }

                    PacketUtils.sendPacketNoEvent(
                        C06PacketPlayerPosLook(
                            mc.thePlayer.posX,
                            mc.thePlayer.posY,
                            mc.thePlayer.posZ,
                            RotationUtils.serverRotation?.yaw!!,
                            RotationUtils.serverRotation?.pitch!!,
                            mc.thePlayer.onGround
                        )
                    )
                    mc.netHandler.addToSendQueue(
                        C08PacketPlayerBlockPlacement(
                            BlockPos(-1, -1, -1),
                            -1,
                            null,
                            0f,
                            0f,
                            0f
                        )
                    )
                    debug("sent placement")

                    if (changed) {
                        PacketUtils.sendPacketNoEvent(C09PacketHeldItemChange(mc.thePlayer.inventory.currentItem))
                        debug("switched back")
                    }
                }
            }
    }

    @EventTarget
    fun onUpdate(event: UpdateEvent) {
        if (boat.get()) {
            if (mc.thePlayer.ridingEntity != null) {
                mc.thePlayer.rotationPitch = (90.0).toFloat()
                mc.thePlayer.swingItem()
                mc.playerController.attackEntity(mc.thePlayer, mc.thePlayer.ridingEntity)
                mc.thePlayer.swingItem()
                mc.playerController.attackEntity(mc.thePlayer, getNearBoat())
                canModify = true
                debug("Destroy Boat")
            }
        }

        if (blockplacement.get()) {
            PacketUtils.sendPacketNoEvent(
                C08PacketPlayerBlockPlacement(
                    BlockPos(Double.NaN, Double.NaN, Double.NaN),
                    1,
                    null,
                    0f,
                    0f,
                    0f
                )
            )
            debug("BlockPlacement")
        }

        if (vulcancombat.get()) {
            if (runReset) {
                runReset = false
                PacketUtils.sendPacketNoEvent(
                    C0BPacketEntityAction(
                        mc.thePlayer,
                        C0BPacketEntityAction.Action.STOP_SPRINTING
                    )
                )
            }
            if (lagTimer.hasTimePassed(currentDelay.toLong()) && BlinkUtils.bufferSize(packetType = "C0FPacketConfirmTransaction") > currentBuffer) {
                updateLagTime()
                BlinkUtils.releasePacket(packetType = "C0FPacketConfirmTransaction", minBuff = currentBuffer)
                debug("C0F-PingTickCounter RELEASE")
            }
            if (decTimer.hasTimePassed(currentDec.toLong()) && currentDec > 0) {
                BlinkUtils.releasePacket(packetType = "C0FPacketConfirmTransaction", amount = 1)
                debug("C0F-PingTickCounter DECREASE")
                decTimer.reset()
            }
        }

        if (oldwatchdog2.get()) {
            // timer1
            if (timerA.get()) {
                if (timerCancelDelay.hasTimePassed(5000)) {
                    timerShouldCancel = true
                    timerCancelTimer.reset()
                    timerCancelDelay.reset()
                }
            }

            // timer2
            if (timerB.get()) {
                if (timerCancelDelay.hasTimePassed(2000)) {
                    timerShouldCancel = true
                    timerCancelTimer.reset()
                    timerCancelDelay.reset()
                }
            }


            //Hypixel Disabler C00
            if (c00Disabler.get()) {
                if (mc.thePlayer.onGround && ClassUtils.isBlockUnder() && mc.thePlayer.fallDistance > 10) {
                    mc.netHandler.addToSendQueue(C00PacketKeepAlive(RandomUtils.nextInt(0, 1000)))
                    debug("Hypixel Disabler C00")
                }
            }

            //Hypixel Disabler C0B & Hypixel Disabler C03
            if (c0BDisabler.get()) {
                if (mc.thePlayer.ticksExisted % 180 == 90) {
                    if (mc.thePlayer.fallDistance > 10) {
                        mc.netHandler.addToSendQueue(C00PacketKeepAlive(RandomUtils.nextInt(0, 1000)))
                        debug("Hypixel Disabler C0B")
                        mc.timer.timerSpeed = 0.8f
                    } else {
                        if (mc.thePlayer.fallDistance < 10) {
                            if (mc.thePlayer.posY == mc.thePlayer.fallDistance.toDouble()) {
                                mc.netHandler.addToSendQueue(C03PacketPlayer(false))
                                if (mc.thePlayer.onGround) mc.timer.timerSpeed = 0.4f
                                if (mc.thePlayer.fallDistance == 0f) mc.netHandler.addToSendQueue(
                                    C03PacketPlayer(true)
                                )
                                debug("Hypixel Disabler C03")
                            }
                        }
                    }
                }
            }
        }

        if (spartancombat.get()) {
            if (msTimer.hasTimePassed(3000L) && keepAlives.size > 0 && transactions.size > 0) {
                PacketUtils.sendPacketNoEvent(keepAlives[keepAlives.size - 1])
                PacketUtils.sendPacketNoEvent(transactions[transactions.size - 1])
                debug("c00 no.${keepAlives.size - 1} sent.")
                debug("c0f no.${transactions.size - 1} sent.")
                keepAlives.clear()
                transactions.clear()
                msTimer.reset()
            }
        }

        if (blockdrop.get()) {
            if (msTimer.hasTimePassed(3000L) && keepAlives.size > 0 && transactions.size > 0) {
                PacketUtils.sendPacketNoEvent(keepAlives[keepAlives.size - 1])
                PacketUtils.sendPacketNoEvent(transactions[transactions.size - 1])

                debug("c00 no.${keepAlives.size - 1} sent.")
                debug("c0f no.${transactions.size - 1} sent.")
                keepAlives.clear()
                transactions.clear()
                msTimer.reset()
            }
        }

        if (silentaccept.get()) {
            if (mc.thePlayer.ticksExisted % 180 == 0) {
                while (packetQueue.size > 22) {
                    PacketUtils.sendPacketNoEvent(packetQueue.poll())
                }
                debug("pushed queue until size < 22.")
            }
        }

        if (latestverus.get()) {
            if (verusAntiFlyCheck.get() && !shouldActive) {
                val flightMod = Launch.moduleManager[Flight::class.java]!!
                if (flightMod.state) {
                    flightMod.state = false
                    chat("You can't fly before successful activation")
                    debug("no fly allowed")
                }
            }
            if (!shouldRun()) {
                msTimer.reset()
                packetQueue.clear()
                return
            }
            if (mc.thePlayer.ticksExisted % 15 == 0) {
                if (verusFakeInput.get()) {
                    mc.netHandler.addToSendQueue(
                        C0CPacketInput(
                            mc.thePlayer.moveStrafing.coerceAtMost(0.98F),
                            mc.thePlayer.moveForward.coerceAtMost(0.98F),
                            mc.thePlayer.movementInput.jump,
                            mc.thePlayer.movementInput.sneak
                        )
                    )
                    debug("c0c")
                }
            }
        }

        if (pingspoof.get()) {
            if (msTimer.hasTimePassed(psfWorldDelay.get().toLong()) && !shouldActive) {
                shouldActive = true
                sendDelay = RandomUtils.nextInt(minpsf.get(), maxpsf.get())
                if (queueBus.size > 0) flush(false)
                msTimer.reset()
                debug("activated. expected next delay: ${sendDelay}ms")
            }

            if (shouldActive) {
                if (msTimer.hasTimePassed(sendDelay.toLong()) && !queueBus.isEmpty()) {
                    flush(true)
                    sendDelay = RandomUtils.nextInt(minpsf.get(), maxpsf.get())
                    msTimer.reset()
                    debug("expected next delay: ${sendDelay}ms")
                }
            }
        }

        if (flag.get()) {
            if (flagMode.get().equals(
                    "packet",
                    true
                ) && mc.thePlayer.ticksExisted > 0 && mc.thePlayer.ticksExisted % flagTick.get() == 0
            ) {
                PacketUtils.sendPacketNoEvent(
                    C04PacketPlayerPosition(
                        mc.thePlayer.posX,
                        -0.08,
                        mc.thePlayer.posZ,
                        mc.thePlayer.onGround
                    )
                )
                debug("flagged")
            }
        }
    }
}